<?php
/**
 * Created by PhpStorm.
 * User: boghra
 * Date: 15/9/2
 * Time: 上午11:08
 */
class ContentAction extends Action{
    public function lists(){
        $cat=M('category')->where(array('en_name'=>array('eq',I('cat_name'))))->find();
        $p_cat=M('category')->where(array('en_name'=>array('eq',I('p_cat_name'))))->find();
        import('ORG.Util.Page');
        $count=M('content')->where(array('con_category'=>array('eq',I('cat_name'))))->count();
        $page=new page($count,10);
        $limit=$page->firstRow.','.$page->listRows;
        $message = M('content')->where(array('con_category'=>array('eq',I('cat_name')),'accept'=>array('eq',1)))->order('id desc')->limit($limit)->select();
        $this->page=$page->show();
        $this->content=$message;
        import('Class.Category',APP_PATH);
        $cate=M('category')->order('sort ASC')->select();
        $this->cate=Category::unlimitedforlayer($cate);
        $this->cate_list=Category::getchilds($cate,I('p_id'));
        $this->you_qing_lian_jie_01=M('link')->order('id desc')->limit(0,12)->select();
        $this->you_qing_lian_jie_02=M('link')->order('id desc')->limit(12,12)->select();
        $this->ri_men=M('content')->order('count desc')->limit(13)->select();
        $this->cat_name=$cat['name'];
        $this->cat_en_name=I('cat_name');
        $this->p_cat_name=$p_cat['name'];
        $this->p_en_cat_name=I('p_cat_name');
        $this->p_id=I('p_id');
        $this->display('list');
    }
    public function show(){
        $db=D('ContentView');
        $id=I('id');
        import('Class.Category',APP_PATH);
        $cate=M('category')->order('sort ASC')->select();
        $this->cate=Category::unlimitedforlayer($cate);
        $this->you_qing_lian_jie_01=M('link')->order('id desc')->limit(0,12)->select();
        $this->you_qing_lian_jie_02=M('link')->order('id desc')->limit(12,12)->select();
        $this->ri_men=M('content')->order('count desc')->limit(13)->select();
        $this->con=$db->where(array('id'=>array('eq',$id)))->select();
        if($this->con[0]['security']==1){
            if(!isset($_SESSION['teachername'])){
                $this->error('你还没有登陆,登陆之后能访问这个题目');
            }
        }
        $category_0=$this->con[0]['con_category'];
        $category_1=M('category')->where(array('en_name'=>array('eq',$category_0)))->find();
        $this->con_category=$category_1['name'];
        $this->con_1=$db->where(array('con_category'=>array('eq',$this->$category_0)))->select();
        $key=null;
        foreach($this->con_1 as $keyp=>$valuep){
            if($valuep['id']==$id){
                $key=$keyp;
            }}
        $this->current=$this->con_1[$key];
        $this->next=$this->con_1[$key+1];
        $this->preve=$this->con_1[$key-1];
        $this->con_list=$db->where(array('con_category'=>array('eq',$category_0)))->limit(13)->select();
        /*
         * */
        $data=array(
            'id'=>$id,
            'count'=>$this->current['count']+1,
        );
        M('content')->where(array('id'=>array('eq',$id)))->save($data);

        /**/
        $con_video = $this->current['con_video'];
        $arr_video = array();
        for ($i = 0; $i < count($con_video); $i++) {
            $arr_video[] = explode(',', $con_video);
        }
        $this->video=$arr_video[0];
        /**/
        $video_name= $this->current['video_old_name'];
        $arr_video_name = array();
        for ($i = 0; $i < count($video_name); $i++) {
            $arr_video_name[] = explode(',', $video_name);
        }
        $this->video_name=$arr_video_name[0];
        /**/
        $file= $this->current['con_file'];
        $arr_file = array();
        for ($i = 0; $i < count($file); $i++) {
            $arr_file[] = explode(',', $file);
        }
        $this->file=$arr_file[0];
        $file_name= $this->current['file_old_name'];
        $arr_file = array();
        for ($i = 0; $i < count(file_name); $i++) {
            $arr_file_name[] = explode(',', $file_name);
        }
        $this->file_name=$arr_file_name[0];
        $this->display();
    }
}